<template>
  <a-card
    :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="学生编号">
              <a-input placeholder="请输入学生编号" v-model="queryParam.stuId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="维护人编号">
              <a-input placeholder="请输入维护人编号" v-model="queryParam.maintainerId"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <a-form-item label="维护时间">
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" class="query-group-cust" v-model="queryParam.maintainTime_begin"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" class="query-group-cust" v-model="queryParam.maintainTime_end"></j-date>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="当前所在城市">
                <j-area-linkage type="cascader" v-model="queryParam.currentLocation" placeholder="请选择省市区"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button id='btnSearch' type="primary" @click="searchQuery" ref="searchRF" icon="search" >查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('就业维护表')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="pcaSlot" slot-scope="text">
          <div>{{ getPcaText(text) }}</div>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <employmen-maintain-modal ref="modalForm" @ok="modalFormOk"></employmen-maintain-modal>
  </a-card>
</template>


<script>

  import '@assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import EmploymenMaintainModal from './EmploymenMaintainModal'
  import {filterMultiDictText,initDictOptions, filterDictText} from '@comp/dict/JDictSelectUtil'
  import Area from '@comp/_util/Area'
  import { httpAction } from '@api/manage'



  export default {
    name: 'EmploymenMaintainList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      EmploymenMaintainModal
    },
    props: ['studentId','triggerStatus'],
    data () {
      return {

        description: '就业维护表管理页面',
        oldStudentId:"",
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'学生姓名',
            align:"center",
            dataIndex: 'stuName'
          },
          {
            title:'学生编号',
            align:"center",
            dataIndex: 'stuId'
          },
          {
            title:'维护人',
            align:"center",
            dataIndex: 'maintainer'
          },
          {
            title:'维护人编号',
            align:"center",
            dataIndex: 'maintainerId'
          },
          {
            title:'维护时间',
            align:"center",
            dataIndex: 'maintainTime'
          },
          {
            title:'维护方式',
            align:"center",
            dataIndex: 'maintainMode'
          },
          {
            title:'当前所在城市',
            align:"center",
            dataIndex: 'currentLocation',
            scopedSlots: {customRender: 'pcaSlot'}
          },
          {
            title:'是否转正',
            align:"center",
            dataIndex: 'regularization'
          },
          {
            title:'薪资变化',
            align:"center",
            dataIndex: 'changeMoney'
          },
          {
            title:'职位变化',
            align:"center",
            dataIndex: 'changePosition'
          },
          {
            title:'是否换工作',
            align:"center",
            dataIndex: 'changeJob'
          },
          {
            title:'协助状态',
            align:"center",
            dataIndex: 'helpStatus',
            customRender: (text, record, index) => {
              //字典值替换通用方法
              return filterDictText(this.helpStatusDictOptions, text);
            }
          },
          {
            title:'是否需要协助',
            align:"center",
            dataIndex: 'helpRequest',
            customRender: (text, record, index) => {
              //字典值替换通用方法
              return filterDictText(this.helpYesNoDictOptions, text);
            }
          },
          {
            title:'遇到的问题',
            align:"center",
            dataIndex: 'maintainQuestion'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/maintain/employmenMaintain/list",
          listByStuIdUrl: "/maintain/employmenMaintain/listByStuId",
          delete: "/maintain/employmenMaintain/delete",
          deleteBatch: "/maintain/employmenMaintain/deleteBatch",
          exportXlsUrl: "/maintain/employmenMaintain/exportXls",
          importExcelUrl: "maintain/employmenMaintain/importExcel",

        },
        dictOptions:{},
        pcaData:'',
        superFieldList:[],
      }
    },
    /*实例创建完成*/
    created() {
      this.pcaData = new Area()
      this.getSuperFieldList();

      debugger
      this.queryParam.stuId=this.studentId;
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      /*触发模拟点击*/
    /* triggerSimulativeClick(){
      if (this.triggerStatus===true){
        document.getElementById("btnSearch").click();
      }
    },*/

      /*如果studentId发生变化，则按最新的回显，重新回载数据并显示，已解决利用关闭弹窗并销毁其子元素*/
      reloadMaintainListByStuId(){
        if (this.oldStudentId!=this.studentId){
          this.reload();

        }

      },

      /*查找对应学生的就业维护信息*/
      queryMaintainByStuId(){
        httpAction(this.url.listByStuIdUrl, {"studentId":this.studentId},"post").then((res)=>{
          if(res.success){
            debugger
          }
        }).finally(() => {
          this.confirmLoading = false;
        })
      },
      getPcaText(code){
        return this.pcaData.getText(code);
      },
      initDictConfig(){
        //初始化字典 - 协助状态
        initDictOptions('help_status').then((res) => {
          if (res.success) {
            this.helpStatusDictOptions = res.result;
          }
        });

        //初始化字典 - 是否需要协助
        initDictOptions('help_Yes_No').then((res) => {
          if (res.success) {
            this.helpYesNoDictOptions = res.result;
          }
        });
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'popup',value:'stuName',text:'学生姓名', popup:{code:'stu_info',field:'stu_id',orgFields:'stu_id',destFields:'stu_id'}})
        fieldList.push({type:'string',value:'stuId',text:'学生编号',dictCode:''})
        fieldList.push({type:'popup',value:'maintainer',text:'维护人', popup:{code:'tj_user_report',field:'id',orgFields:'id',destFields:'maintainer'}})
        fieldList.push({type:'string',value:'maintainerId',text:'维护人编号',dictCode:''})
        fieldList.push({type:'datetime',value:'maintainTime',text:'维护时间'})
        fieldList.push({type:'string',value:'maintainMode',text:'维护方式',dictCode:''})
        fieldList.push({type:'pca',value:'currentLocation',text:'当前所在城市'})
        fieldList.push({type:'string',value:'regularization',text:'是否转正',dictCode:''})
        fieldList.push({type:'string',value:'changeMoney',text:'薪资变化',dictCode:''})
        fieldList.push({type:'string',value:'changePosition',text:'职位变化',dictCode:''})
        fieldList.push({type:'string',value:'changeJob',text:'是否换工作',dictCode:''})
        fieldList.push({type:'string',value:'helpStatus',text:'协助状态',dictCode:'help_status'})
        fieldList.push({type:'string',value:'helpRequest',text:'是否需要协助',dictCode:'help_Yes_No'})
        fieldList.push({type:'Text',value:'maintainQuestion',text:'遇到的问题',dictCode:''})
        this.superFieldList = fieldList
      }
    }/*,
    mounted() {
      debugger
      this.oldStudentId=this.studentId;
      this.reloadMaintainListByStuId();
    }*/

  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>